﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Collections;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class MP_FieldDutiesDtls : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        IFieldDutyBLL dutyBLL = new FieldDutyBLL();
        IFieldDutyDtlsBLL dutyDtlsBll = new FieldDutyDtlsBLL();
        IDutyBLL Duty = new DutyBLL();

        private object _dataItem = null;
        protected void Page_Load(object sender, EventArgs e)
        {           

            if (DataItem != null)
            {
                LoadHeader();
                FillDataToDuty();

                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblSeq.Text = DataBinder.Eval(DataItem, "field_duty_dtls_seq").ToString();
                    cmbDuty.SelectedValue = Convert.ToString(DataBinder.Eval(DataItem, "duty_seq"));
                    txtNo.Text = DataBinder.Eval(DataItem, "seq_no").ToString();
                    txtDutyDescr.Text = DataBinder.Eval(DataItem, "descr").ToString();
                }

                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        public void LoadHeader()
        {
            lblFieldSeq.Text = Session["FieldSeq"].ToString();
            lblClassSeq.Text = Session["ClassSeq"].ToString();
       }

        public void FillDataToDuty()
        {
            
            IList<DutyInfo> info = Duty.ListDuties(null);

            cmbDuty.DataSource = info;
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            dutyDtlsBll.Update(Int32.Parse(lblSeq.Text.Trim())
                , Int32.Parse(lblFieldSeq.Text.Trim())
                , cmbDuty.SelectedValue
                , txtNo.Text.Trim()
                , txtDutyDescr.Text
                , ssMng.EmpSeqI);
        }

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            dutyDtlsBll.Insert(lblFieldSeq.Text.Trim()
                , lblClassSeq.Text.Trim()
                , cmbDuty.SelectedValue
                , txtNo.Text.Trim()
                , txtDutyDescr.Text
                , ssMng.EmpSeqI);

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}